home *** CD-ROM | disk | FTP | other *** search
- #! /bin/sh
- # postinst script for cupsys
- #
- # see: dh_installdeb(1)
-
- set -e
-
- # summary of how this script can be called:
- # * <postinst> `configure' <most-recently-configured-version>
- # * <old-postinst> `abort-upgrade' <new version>
- # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
- # <new-version>
- # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
- # <failed-install-package> <version> `removing'
- # <conflicting-package> <version>
- # for details, see /usr/doc/packaging-manual/
- #
- # quoting from the policy:
- # Any necessary prompting should almost always be confined to the
- # post-installation script, and should be protected with a conditional
- # so that unnecessary prompting doesn't happen if a package's
- # installation fails and the `postinst' is called with `abort-upgrade',
- # `abort-remove' or `abort-deconfigure'.
-
- # Debconf
- . /usr/share/debconf/confmodule
-
- # Default Configuration file
- if [ -e /etc/default/cupsys ]; then
- . /etc/default/cupsys
- fi
-
- case "$1" in
- configure)
- [ -f /etc/cups/printers.conf.save ] && mv /etc/cups/printers.conf.save /etc/cups/printers.conf
- [ -f /etc/cups/classes.conf.save ] && mv /etc/cups/classes.conf.save /etc/cups/classes.conf
-
- # Set up lpadmin group.
- if [ -z "`getent group lpadmin`" ]; then
- addgroup --system lpadmin
- fi
- if [ -n "`getent group lpadmin | awk -F: '{ print $4 }' | awk -F, '{ for (i=1; i <= NF; i++ ) print $i }' |grep '^root$'`" ]; then
- # Bug#214746
- echo "Deleting root from lpadmin group. If you use NIS/LDAP, change this manually."
- deluser root lpadmin || true
- fi
-
- # Set up cupsys user.
- if [ -z "`getent passwd cupsys`" ]; then
- adduser --quiet --system --no-create-home --ingroup lpadmin cupsys
- fi
-
- # necessary for access to local parallel and usb printers
- adduser --quiet cupsys lp
- # necessary for access to local serial printers
- adduser --quiet cupsys dialout
- # necessary for web authentication
- # disabled by default since lpadmin membership is sufficient
- # adduser --quiet cupsys shadow
- # necessary for access to printer/scanner combo devices
- if [ -z "`getent group scanner`" ]; then
- addgroup --system scanner
- fi
- adduser --quiet cupsys scanner
-
- if [ -d /etc/cups/certs ]; then
- rm -rf /etc/cups/certs
- fi
- if [ -d /var/spool/cups/certs ]; then
- mv /var/spool/cups/certs/* /var/run/cups/certs || true
- rm -rf /var/spool/cups/certs
- fi
- if [ -d /var/lib/cups/certs ]; then
- rm -rf /va/lib/cups/certs
- fi
- if [ -L /usr/share/ppd/cups-transitional-dir ]; then
- rm -f /usr/share/ppd/cups-transitional-dir
- fi
- if [ -L /usr/share/cups/model/cups-included ]; then
- rm -f /usr/share/cups/model/cups-included
- fi
-
- [ -f /etc/cups/ppds.dat ] && mv /etc/cups/ppds.dat /var/cache/cups/ppd
-
- # Set up smb backend by symlinking to smbspool.
- if [ -x /usr/bin/smbspool -a ! -e /usr/lib/cups/backend/smb ]; then
- ln -sf /usr/bin/smbspool /usr/lib/cups/backend/smb
- fi
-
- # Generate raw MIME handling files if they don't already exist.
- if [ ! -e /etc/cups/raw.types ]; then
- cat >/etc/cups/raw.types <<EOF
- # This file was generated by the cupsys package. You may change it, or
- # reconfigure this file with dpkg-reconfigure. If it is removed, it
- # will be regenerated by the package scripts.
-
- application/octet-stream
- EOF
- fi
- if [ ! -e /etc/cups/raw.convs ]; then
- cat >/etc/cups/raw.convs <<EOF
- # This file was generated by the cupsys package. You may change it, or
- # reconfigure this file with dpkg-reconfigure. If it is removed, it
- # will be regenerated by the package scripts.
-
- application/octet-stream application/vnd.cups-raw 0 -
- EOF
- fi
-
- # Set up raw printing of application/octet-stream if desired.
- db_fget cupsys/raw-print changed
- if [ "$RET" = "true" ]; then
- mv /etc/cups/raw.convs /etc/cups/raw.convs-convert
- db_get cupsys/raw-print
- if [ "$RET" = "true" ]; then
- sed 's/^\s*#\s*application/application/' \
- < /etc/cups/raw.convs-convert > /etc/cups/raw.convs
- else
- sed 's/^application/#application/' \
- < /etc/cups/raw.convs-convert > /etc/cups/raw.convs
- fi
- rm -f /etc/cups/raw.convs-convert
- db_fset cupsys/raw-print changed false
- fi
- # Set up backends
- #db_fget cupsys/backend changed
- #if [ "$RET" = "true" ] || [ -z "$2" ]; then
- db_get cupsys/backend && SELECTED=$RET
- list=`echo $SELECTED | sed -e 's/, /,/g'`
- save_IFS=$IFS
- IFS=,
- (cd /usr/lib/cups/backend && rm -f http ipp lpd parallel scsi serial socket usb snmp)
- for module in $list; do
- ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
- if [ "$module" = "ipp" ]; then
- ln /usr/lib/cups/backend/ipp /usr/lib/cups/backend/http
- fi
- done
- IFS=$save_IFS
- db_fset cupsys/backend changed false
- #fi
-
- # Assure that the special permissions of the lpd backend are also set
- # for the link in /usr/lib/cups/backend/
- if [ -e /usr/lib/cups/backend/lpd ]; then
- chown root:lp /usr/lib/cups/backend/lpd
- chmod 4754 /usr/lib/cups/backend/lpd
- fi
-
- # In cupsys 1.2.8-0ubuntu3 the defaults for the active backends
- # changed. snmp, scsi, and serial got added. So activate these
- # backends.
- if dpkg --compare-versions "$2" lt-nl "1.2.8-0ubuntu3"; then
- for module in snmp scsi serial; do
- [ -e /usr/lib/cups/backend/$module ] || \
- ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
- done
- fi
-
- # In cupsys from 1.2.8-0ubuntu3 to 1.2.8-0ubuntu6 there were bugs
- # which messed up the backend configuration. Reset to all backends
- # being active when updating from one of these versions. Correct also
- # if we update from 1.2.8-0ubuntu7 as the user can have updated from
- # one of the broken versions to 1.2.8-0ubuntu7.
- if dpkg --compare-versions "$2" ge "1.2.8-0ubuntu3" && \
- dpkg --compare-versions "$2" lt-nl "1.2.8-0ubuntu8" ; then
- for module in ipp lpd parallel scsi serial snmp socket usb; do
- [ -e /usr/lib/cups/backend/$module ] || \
- ln /usr/lib/cups/backend-available/$module /usr/lib/cups/backend/$module
- if [ "$module" = "ipp" ]; then
- [ -e /usr/lib/cups/backend/http ] || \
- ln /usr/lib/cups/backend/ipp /usr/lib/cups/backend/http
- fi
- done
- fi
-
- # Resync Debconf database with real state
- list=`( cd /usr/lib/cups/backend && for f in ipp lpd parallel scsi serial socket usb snmp; do [ -e $f ] && echo -n "$f, "; done ) | sed -e 's/, $//'`
- db_set cupsys/backend $list;
-
- # Create password file for Digest authentication
- # (removed: Debian CUPS uses PAM and basic authentication)
- #db_get cupsys/adminpassword
- #VAL=$(echo -n "root:CUPS:$RET" | md5sum | cut -d' ' -f1)
- #if [ -f /etc/cups/passwd.md5 ]; then
- # if [ "$(grep "^root:" /etc/cups/passwd.md5)" ]; then
- # sed -e "s/^root:lpadmin:.*/root:lpadmin:$VAL/" /etc/cups/passwd.md5 > /etc/cups/passwd.md5.$$
- # mv /etc/cups/passwd.md5.$$ /etc/cups/passwd.md5
- # else
- # echo "root:lpadmin:$VAL" >> /etc/cups/passwd.md5
- # fi
- #else
- # echo "root:lpadmin:$VAL" > /etc/cups/passwd.md5
- # chown root:nogroup /etc/cups/passwd.md5
- # chmod 600 /etc/cups/passwd.md5
- #fi
-
- # Revert to single file
- if [ -f /etc/cups/cups.d/ports.conf -o -f /etc/cups/cups.d/browse.conf ]; then
- perl -e 'sub readfile { local($_) = @_; open(F, $_); while (<F>) { print; } }; while (<STDIN>) { s#^Include\s+(/etc/cups/cups.d/(?:ports.conf|browse.conf))#&readfile($1)#ei; print;}' < /etc/cups/cupsd.conf > /etc/cups/cupsd.conf.$$
- mv /etc/cups/cupsd.conf.$$ /etc/cups/cupsd.conf
- rm -f /etc/cups/cups.d/ports.conf /etc/cups/cups.d/browse.conf
- rmdir /etc/cups/cups.d 2>/dev/null || /bin/true
- fi
- #
- # Create /etc/cups/cups.d/ports.conf and /etc/cups/cups.d/browse.conf
- #db_get cupsys/ports
- #VAL=$(echo "$RET" | perl -e '$ret = ""; while (<STDIN>) { chomp;
- # @values = split(/\s+/);
- # foreach(@values) {
- # if (/^\d+$/ && $_ >= 0 && $_ < 65536) {
- # # PORT
- # $ret .= "Port $_\\n";
- # } elsif (/^\d+\.\d+\.\d+\.\d+$/ || /^\d+\.\d+\.\d+\.\d+:\d+$/) {
- # # IP
- # $ret .= "Listen $_\\n";
- # } elsif (/^[a-zA-Z0-9-_.*]+$/ || /^[a-zA-Z0-9-_.*]+:\d+$/) {
- # my($tmp) = $_;
- # if (/^[a-zA-Z0-9-_.*]+:(\d+)$/) {
- # if ($1 < 0 || $1 > 65535) {
- # # ERROR
- # $ret = "";
- # last;
- # }
- # }
- # # HOSTNAME
- # $ret .= "Listen $_\\n";
- # } elsif (/^\//) {
- # # domain socket
- # $ret .= "Listen $_\\n";
- # } else {
- # # ERROR
- # $ret = "";
- # last;
- # }
- # }
- # print $ret;
- # }')
-
- #if [ -z "$VAL" ]; then
- # echo "Error: debconf has an invalid value. Run 'dpkg-reconfigure cupsys' again."
- # return 1
- #else
- # /bin/echo -e -n "$VAL" > /etc/cups/cups.d/ports.conf
- #fi
-
- #db_get cupsys/browse
- #if [ "$RET" = "true" ]; then
- # /bin/echo "Browsing on" > /etc/cups/cups.d/browse.conf
- #else
- # /bin/echo "Browsing off" > /etc/cups/cups.d/browse.conf
- #fi
-
- # permission configuration
- chown root:lp /etc/cups ; chmod 3755 /etc/cups
- chown cupsys:root /etc/cups/cupsd.conf ; chmod 644 /etc/cups/cupsd.conf
- chown root:lp /etc/cups/ppd ; chmod 755 /etc/cups/ppd
- chown cupsys:shadow /usr/lib/cups/daemon/cups-check-pam-auth
- chmod 2754 /usr/lib/cups/daemon/cups-check-pam-auth
- if [ ! -d /var/run/cups/certs ]; then
- mkdir /var/run/cups/certs && chown cupsys:lpadmin /var/run/cups/certs \
- && chmod 511 /var/run/cups/certs
- fi
- if [ -f /etc/cups/classes.conf ]; then
- chown root:lp /etc/cups/classes.conf ; chmod 600 /etc/cups/classes.conf
- fi
- if [ -f /etc/cups/printers.conf ]; then
- chown root:lp /etc/cups/printers.conf ; chmod 600 /etc/cups/printers.conf
- fi
-
- # fix permissions for upgrades which might have written cache files as
- # root
- if [ -d /var/cache/cups ]; then
- chown -R cupsys:lp /var/cache/cups || true
- fi
-
- # symlink snakeoil SSL certificate if present
- if dpkg --compare-versions "$2" le "1.2.1-2ubuntu1" && \
- [ -e /etc/ssl/certs/ssl-cert-snakeoil.pem -a \
- -e /etc/ssl/private/ssl-cert-snakeoil.key -a \
- -n "`getent group ssl-cert`" -a \
- ! -e /etc/cups/ssl/server.crt -a \
- ! -e /etc/cups/ssl/server.key ]; then
- ln -s /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/cups/ssl/server.crt
- ln -s /etc/ssl/private/ssl-cert-snakeoil.key /etc/cups/ssl/server.key
- adduser cupsys ssl-cert
- fi
-
-
- # Remove shutdown and reboot links; this init script does not need them.
- if dpkg --compare-versions "$2" lt "1.2.1-2ubuntu3"; then
- rm -f /etc/rc0.d/K19cupsys /etc/rc6.d/K19cupsys
- fi
-
- # remove shadow privilege from cupsys (admins might have manually added
- # cupsys to shadow to enable the web interface in earlier versions)
- if dpkg --compare-versions "$2" le-nl "1.2.2-0ubuntu2"; then
- deluser --quiet cupsys shadow 2>/dev/null || true
- fi
-
- # Add symlink to local files required by LSB
- #if [ ! -e /usr/share/ppd/1-local-admin -a ! -L /usr/share/ppd/1-local-admin ]; then
- # ln -s /usr/local/share/ppd /usr/share/ppd/1-local-admin
- #fi
- #if [ ! -e /usr/share/ppd/2-third-party -a ! -L /usr/share/ppd/2-third-party ]; then
- # ln -s /opt/share/ppd /usr/share/ppd/2-third-party
- #fi
-
- ;;
-
- abort-upgrade|abort-remove|abort-deconfigure)
-
- ;;
-
- *)
- echo "postinst called with unknown argument \`$1'" >&2
- exit 0
- ;;
- esac
-
- # dh_installdeb will replace this with shell code automatically
- # generated by other debhelper scripts.
-
- # Automatically added by dh_installdocs
- if [ "$1" = configure ] && which install-docs >/dev/null 2>&1; then
- install-docs -i /usr/share/doc-base/cupsys
- fi
- # End automatically added section
- # Automatically added by dh_installinit
- if [ -x "/etc/init.d/cupsys" ]; then
- update-rc.d cupsys multiuser 19 >/dev/null
- if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
- invoke-rc.d cupsys start || exit $?
- else
- /etc/init.d/cupsys start || exit $?
- fi
- fi
- # End automatically added section
- # Automatically added by dh_usrlocal
- if [ "$1" = configure ]; then
- (
- while read line; do
- set -- $line
- dir="$1"; mode="$2"; user="$3"; group="$4"
- if [ ! -e "$dir" ]; then
- if mkdir "$dir" 2>/dev/null; then
- chown "$user":"$group" "$dir"
- chmod "$mode" "$dir"
- fi
- fi
- done
- ) << DATA
- /usr/local/share 2775 root staff
- /usr/local/share/ppd 2775 root staff
- DATA
- fi
- # End automatically added section
-
-
- db_stop
- exit 0
-
-
-